package com.hmall.user.controller;

import com.hmall.user.pojo.Address;
import com.hmall.user.pojo.User;
import com.hmall.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;


    @GetMapping("/address/uid")
    public List<Address> getAddress() {
        return userService.getAddress();
    }

    @GetMapping("/address/{addressId}")
    public Address queryAddress(@PathVariable("addressId") Long id) {
        return userService.queryAddress(id);
    }

    @GetMapping("/user/findUser/{userId}")
    User findUser(@PathVariable("userId") Long userId) {
        return userService.getById(userId);
    }

    @PutMapping("/pay/{userId}/{num}")
    Boolean UserPay(@PathVariable("userId") Long userId, @PathVariable("num") Long num) {
        return userService.pay(userId, num);
    }

    @GetMapping("/query/balance/{userId}")
    Long queryBalance(@PathVariable("userId") Long userId){
        return userService.queryBalance(userId);
    }
}
